package com.ssy.lingxi.member.merchant.model.constant;

import com.ssy.lingxi.common.language.LanguageHolder;
import com.ssy.lingxi.member.merchant.model.vo.basic.response.DropdownItem;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 拜访类型枚举
 * @author 万宁
 * @version 2.0.0
 * @date 2021-05-25
 */
public enum VisitTypeEnum {

    /**
     * 拜访类型
         1、年度拜访
         2、季度拜访
         3、月度拜访
         4、订单拜访
         5、引入拜访
         6、负责人变更拜访
         7、其他拜访
     */

    /**
     * 1:年度拜访
     */
    ANNUAL_VISIT(1, "年度拜访"),

    /**
     * 2: 季度拜访
     */
    QUARTERLY_VISIT(2, "季度拜访"),

    /**
     * 3: 月度拜访
     */
    MONTHLY_VISIT(3, "月度拜访"),

    /**
     * 4: 订单拜访
     */
    ORDER_VISIT(4, "订单拜访"),

    /**
     * 5: 引入拜访
     */
    INTRODUCTION_VISIT(5, "引入拜访"),

    /**
     * 6: 负责人变更拜访
     */
    PERSON_IN_CHARGE_CHANGE_VISIT(6, "负责人变更拜访"),

    /**
     * 7: 其他拜访
     */
    OTHER_VISITS(7, "其他拜访");

    VisitTypeEnum(Integer code, String msg) {
        this.code = code;
    }

    private final Integer code;

    public Integer getCode() {
        return code;
    }

    public String getMsg() {
        return LanguageHolder.getName(this.getClass(), this.getCode());
    }

    public static List<DropdownItem> toDropdownList() {
        List<DropdownItem> items = Arrays.stream(VisitTypeEnum.values()).sorted(Comparator.comparingInt(VisitTypeEnum::getCode)).map(e -> new DropdownItem(e.getCode(), e.getMsg())).collect(Collectors.toList());
        items.add(0 , new DropdownItem(0, MemberStringEnum.CHOOSE.getName()));
        return items;
    }

    public static List<DropdownItem> toEditableDropdownList() {
        return Arrays.stream(VisitTypeEnum.values()).sorted(Comparator.comparingInt(VisitTypeEnum::getCode)).map(e -> new DropdownItem(e.getCode(), e.getMsg())).collect(Collectors.toList());
    }

    public static String getCodeMsg(Integer code) {
        return LanguageHolder.getName(VisitTypeEnum.class, code);
    }

    /**
     * 根据枚举值获得名称
     * @param code 枚举值
     * @return 发票名称
     */
    public static String getNameByCode(Integer code) {
        return LanguageHolder.getName(VisitTypeEnum.class, code);
    }
}
